package TruongNhaLib;
import java.util.ArrayList;

import www.truongnha.com.R;
import android.content.Context;
import android.text.Html;
import android.text.SpannableString;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.BufferType;

public class EListAdapterMarkForStd extends BaseExpandableListAdapter{
	private LayoutInflater inflater;
	private ArrayList<SubjectMark> mParent;
	public EListAdapterMarkForStd(Context context, ArrayList<SubjectMark> parent){
		mParent = parent;
	    inflater = LayoutInflater.from(context);
	}
	//counts the number of group/parent items so the list knows how many times calls getGroupView() method
    public int getGroupCount() {
        return mParent.size();
    }
    //counts the number of children items so the list knows how many times calls getChildView() method
    public int getChildrenCount(int i) {
        return mParent.get(i).getChildNumber();//4
    }
    //gets the title of each parent/group
    public Object getGroup(int i) {
        Log.d("getGroup : ", i +" ");
        return mParent.get(i).getTitle();
    }
    public Object getStatus(int i){
    	return mParent.get(i).getStatus();
    }
    //gets the name of each item
    public Object getChild(int i, int i1) {
        return mParent.get(i).getChilds(i1);
    }
    public SpannableString getspanChilds(int i, int i1){
    	return mParent.get(i).getSpanChilds(i1);
    }
    
    public long getGroupId(int i) {
        return i;
    }
    public long getChildId(int i, int i1) {
        return i1;
    }
    public boolean hasStableIds() {
        return true;
    }
    //in this method you must set the text to see the parent/group on the list
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.e_list_parrent, viewGroup,false);
        }
        TextView textView = (TextView) view.findViewById(R.id.list_item_text_view);
        //"i" is the position of the parent/group in the list
        textView.setText(getGroup(i).toString());
        Button status = (Button) view.findViewById(R.id.status);
        if(!getStatus(i).toString().equals("0")){
        	status.setVisibility(View.VISIBLE);
        	status.setText(getStatus(i).toString());
        } else{
        	status.setVisibility(View.GONE);
        }
        //return the entire view
        return view;
    }
    //in this method you must set the text to see the children on the list
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.e_list_child, viewGroup,false);
        }
        TextView textView = (TextView) view.findViewById(R.id.list_item_text_child);
        //"i" is the position of the parent/group in the list and 
        //"i1" is the position of the child
        textView.setText(mParent.get(i).getSpanChilds(i1), BufferType.SPANNABLE);
        //textView.setText(Html.fromHtml("<font color='#EE0000'>red, 10, 9</font>"));
        //return the entire view
        return view;
    }
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
    public void selectGroup(View view, int i){
        Button status = (Button) view.findViewById(R.id.status);
        Log.d("select group : ", i +" ");
        status.setVisibility(View.GONE);
    }
}